// 纯JS省市区三级联动
// 2011-11-30 by http://www.cnblogs.com/zjfree
var mediumInit = function (_oneMedium, _twoMedium, _thrMedium, defaultoneMedium, defaulttwoMedium, defaultArea) {
    var oneMedium = document.getElementById(_oneMedium);
    var twoMedium = document.getElementById(_twoMedium);
    var thrMedium = document.getElementById(_thrMedium);

    function cmbSelect(cmb, str) {
        for (var i = 0; i < cmb.options.length; i++) {
            if (cmb.options[i].value == str) {
                cmb.selectedIndex = i;
                return;
            }
        }
    }

    function cmbAddOption(cmb, str, obj) {
        var option = document.createElement("OPTION");
        cmb.options.add(option);
        option.innerText = str;
        option.value = str;
        option.obj = obj;
    }

    function changetwoMedium() {
        thrMedium.options.length = 0;
        if (twoMedium.selectedIndex == -1) return;
        var item = twoMedium.options[twoMedium.selectedIndex].obj;
        for (var i = 0; i < item.areaList.length; i++) {
            cmbAddOption(thrMedium, item.areaList[i], null);
        }
        cmbSelect(thrMedium, thrMediumi);
    }

    function changeoneMedium() {
        twoMedium.options.length = 0;
        twoMedium.onchange = null;
        if (oneMedium.selectedIndex == -1) return;
        var item = oneMedium.options[oneMedium.selectedIndex].obj;
        for (var i = 0; i < item.citiesList.length; i++) {
            cmbAddOption(twoMedium, item.citiesList[i].name, item.citiesList[i]);
        }
        cmbSelect(twoMedium, twoMediumi);
        changetwoMedium();
        twoMedium.onchange = changetwoMedium;
    }

    for (var i = 0; i < MediumList.length; i++) {
        cmbAddOption(oneMedium, MediumList[i].name, MediumList[i]);
    }
    cmbSelect(oneMedium, oneMediumi);
    changeoneMedium();
    oneMedium.onchange = changeoneMedium;
}

